package Test;

import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowsEventTest {
    private  static void Windows(){
        JFrame frame = new JFrame("窗口");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500,500);
        frame.setVisible(true);

        frame.addWindowListener(new WindowListener() {
            @Override
            public void windowOpened(WindowEvent e) {
                System.out.println("窗体打开事件");
            }

            @Override
            public void windowClosing(WindowEvent e) {
                System.out.println("窗体正在关闭事件");
            }

            @Override
            public void windowClosed(WindowEvent e) {
                System.out.println("窗体关闭事件");
            }

            @Override
            public void windowIconified(WindowEvent e) {
                System.out.println("窗体图表化事件");
            }

            @Override
            public void windowDeiconified(WindowEvent e) {
                System.out.println("窗体取消图表化事件");
            }

            @Override
            public void windowActivated(WindowEvent e) {
                System.out.println("窗体激活事件");
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
                System.out.println("窗体停用事件");
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(WindowsEventTest::Windows);
    }
}
